package com.architecture.bo;

import java.io.Serializable;
import java.util.Collection;

import com.architecture.entity.Entity;
import com.architecture.persistence.dao.DAO;

/**
 * <p>Base of all business objects.</p> 
 * @author JR
 * @param <E>
 */
public abstract class Bo<E extends Entity> {
	
	/**
	 * <p>Returns the data access object layer.</p>
	 * @return DAO<E>
	 */
	protected abstract DAO<E> getDao();
	
	/**
	 * <p>List all entities.<p>
	 * @return Collection
	 */
	public Collection<E> list(){
		return this.getDao().list();
	}
	
	/**
	 * <p>List entities using a interval.<p>
	 * @param start
	 * @param end
	 * @return Collection
	 */
	public Collection<E> list(final int start, final int end){
		 return this.getDao().list(start, end);
	}
	
	/**
	 * <p>Creates a new entity.</p>
	 * @param entity
	 * @return <code>Serializable</code>
	 */
	public Serializable create(E entity){
		return this.getDao().create(entity);
	}
	
	/**
	 * <p>Reads data of an entity using the identifier of the entity.</p>
	 * @param id
	 * @return E
	 */
	public E read(final Serializable id){
		return this.getDao().read(id);
	}
	
	/**
	 * <p>Update data of an entity.</p>
	 * @param entity
	 */
	public void update(E entity){
		this.getDao().update(entity);
	}
	
	/**
	 * <p>Delete an entity using its identifier.<p>
	 * @param id
	 */
	public void delete(Serializable id){
		this.getDao().delete(id);
	}
}
